package com.cskaoyan.utils;

import com.github.pagehelper.PageHelper;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {

    public static String getMd5(String content) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance("md5");
        byte[] bytes = content.getBytes();
        byte[] result = md5.digest(bytes);
        StringBuffer stringBuffer = new StringBuffer();
        for (byte b : result) {
            String s = Integer.toHexString(b & 0xff);
            if (s.length() == 1) {
                stringBuffer.append("0");
            }
            stringBuffer.append(s);
        }
        return stringBuffer.toString();
    }

    public static String getMd5(String content, String salt) throws Exception {
        content = content +salt;
        String md5 = getMd5(content);
        return md5;
    }

    public static String getMultiMd5(String content) throws Exception {
        return getMd5(getMd5(getMd5(content, "cskaoyanmall")));
    }

    public static String getMd5Salt(String content) throws Exception {
        return "$2a$10$" + getMd5(content);
    }

}
